use strict ; use warnings ; 

package SelfReflector ; 
use lib '.' ; require Exporter;

use File::Find ; 
# @ISA = qw(AutoLoader Exporter);
my @EXPORT = qw(ListProductFiles);

# the hash holding the vars 
our $confHolder = () ; 




sub AUTOLOAD {
	no strict 'refs'; 
    my $name = our $AUTOLOAD;
    *$AUTOLOAD = sub { 
	my $msg = "BOOM! BOOM! BOOM! \n RunTime Error !!!\nI see an undefined function $name(@_)\n" ;
	my $ExcelToHtml = new QALogger(	\$confHolder	) ; #try to create the ExcelToHtml obj might fail if 
	if ($ExcelToHtml)	{$ExcelToHtml->logmsg($msg);}
	else 			{print $msg ; }
    };
    goto &$AUTOLOAD;    # Restart the new routine.
} #eof sub 	


sub DESTROY 
{
	my $self = shift;
	#debug print "the DESTRUCTOR is called  \n" ; 
	return ; 
} 


#CONSTRUCTOR
sub new	{
	my $self = shift;
	$confHolder = ${ shift @_ } ; 											
	
	$self = {} ;
	bless $self ; 
	return $self ; 
	
} #eof sub


sub ListProductFiles {

my $ProductVersionDir = $confHolder->{'ProductVersionDir'} ; 
my $FileToPrintTo = $confHolder->{'ProductFilesFile'} ; 


my @FilesToHandle = ();
my $StrToPrint = ()  ;

#add only files of type filePattern recursively from the $currentWorkingDir
find( sub { push @FilesToHandle, $File::Find::name   }, $ProductVersionDir) ;

	foreach my $file ( @FilesToHandle  ) 
	{
		$StrToPrint .= "$file\n" ;   
	}
	
	chomp ( $StrToPrint ) ; 
	
	my $objFileHandler = new FileHandler ( \$confHolder ) ; 
	$objFileHandler->PrintToFile( $FileToPrintTo , $StrToPrint ) ; 


} #eof sub 


sub ListProductFilesRelative {

my $ProductVersionDir = $confHolder->{'ProductVersionDir'} ; 
my $FileToPrintTo = $confHolder->{'ProductFilesRelativeFile'} ; 
my $ProductDir = $confHolder->{'ProductDir'} . '/' ; 

my @FilesToHandle = ();
my $StrToPrint = ()  ;
my $objLogger = new Logger ( \$confHolder ) ; 

#add only files of type filePattern recursively from the $currentWorkingDir
find( sub { push @FilesToHandle, $File::Find::name   }, $ProductVersionDir) ;

	foreach my $file ( @FilesToHandle  ) 
	{
		$objLogger->LogDebugMsg ( "BEFORE \$file is \n $file " ) ; 
		# x2f - hex for /
		my $StrToRemove = "$ProductDir" ; 
		
		$file =~ s/$StrToRemove//gi ; 

		$objLogger->LogDebugMsg ( "AFTER \$file is \n $file " ) ; 


		$StrToPrint .= "$file\n" ;   
	}
	
	chomp ( $StrToPrint ) ; 
	
	my $objFileHandler = new FileHandler ( \$confHolder ) ; 
	$objFileHandler->PrintToFile( $FileToPrintTo , $StrToPrint ) ; 


} #eof sub 




1;

__END__


#	This package is responsible for reading the ini-files
#	it is used by every other application and module in the Product
#use vars qw(%variables);
# Version: 
# 1.0 - Initial creation added the listing of product ( solution ) files 
